]>
Commit | Line | Data |
---|---|---|
1 | import SwiftUI | |
2 | ||
3 | struct MapBlockers: View { | |
4 | ||
5 | let mapSize: CGSize | |
6 | let vertexSize: CGSize | |
7 | let blockers: [Blocker] | |
8 | ||
9 | let cornerSize = CGSize(width: 2.0, height: 2.0) | |
10 | ||
11 | var body: some View { | |
12 | ForEach(blockers, id: \.id) { vertex in | |
13 | Path { path in | |
14 | path.addRoundedRect( | |
15 | in: CGRect( | |
16 | origin: CGPoint( | |
17 | x: w(vertex.position.x) + 3 * vertexSize.width, | |
18 | y: h(vertex.position.y) - vertexSize.height * 2 / 3), | |
19 | size: CGSize(width: vertexSize.width / 2, height: vertexSize.height * 2) | |
20 | ), cornerSize: cornerSize) | |
21 | }.fill(Color.map.blockerColor) | |
22 | } | |
23 | } | |
24 | ||
25 | func h(_ dimension: CGFloat) -> CGFloat { | |
26 | max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0)) | |
27 | } | |
28 | ||
29 | func w(_ dimension: CGFloat) -> CGFloat { | |
30 | max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) | |
31 | } | |
32 | } | |
33 | ||
34 | #Preview { | |
35 | MapBlockers( | |
36 | mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0), | |
37 | blockers: [ | |
38 | Blocker(id: 0, position: CGPoint(x: 50.0, y: 50.0)), | |
39 | Blocker(id: 1, position: CGPoint(x: 10.0, y: 20.0)), | |
40 | ]) | |
41 | } |